<?php

namespace app\user\controller\mall;

use app\common\controller\Userend;
use think\Db;
/**
 * Ajax异步请求接口
 * @internal
 */
class Ajax extends Userend
{

    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 读取商城分类数据,联动列表
     */
    public function goodscats()
    {
        $province = $this->request->get('province');
        $city = $this->request->get('city');
        $where = ['pid'=> 0,'dataflag'=> 1];
        $provincelist = null;
        if ($province !== '') {
            if ($province) {
                $where = ['pid'=>$province,'dataflag'=>1];
                
            }
            if ($city !== '') {
                if ($city) {
                    $where = ['pid'=>$city,'dataflag'=>1];
                    
                }
                $provincelist = Db::name('mall_goods_cat')->where($where)->field('id as value,name')->order('weigh desc,id')->select();
            }
        }
        $this->success('', null, $provincelist);
    }
    
    /**
     * 读取商城分类数据,联动列表
     */
    public function shopcats()
    {
        $pid = $this->request->get('pid');
        $where = ['shop_id'=>cookie('shop_id'),'status'=>'normal','pid'=>0];
        $categorylist = null;
        if ($pid !== '') {
            if ($pid) {
                $where = ['shop_id'=>cookie('shop_id'),'status'=>'normal','pid'=>$pid];
            }
            
            $categorylist = Db::name('mall_shop_cats')->where($where)->field('id as value,name')->order('sort,id')->select();
        }
        $this->success('', null, $categorylist);
    }
    
    /**
     * 读取商城分类数据,联动列表
     */
    public function catbrand()
    {
        $catid = $this->request->get('catid');
        $brand_model = new \app\common\model\mall\goods\Brand;
        $list = $brand_model->listQuery($catid);        
        $this->success('', null, $list);
    }
    
}
